Toast
The toast view modifier displays a temporary notification message (toast) over the current view.
It is typically used to show short feedback messages such as “Saved successfully,” “Action completed,” or “Network error.”
You can show a simple text message or provide a fully custom view as the toast’s content. You can also control its duration, position, background color, text color, corner radius, and shadow style.
Type Definition
Property Descriptions
isPresented: boolean and onChanged(isPresented: boolean): void
Description:
Uses the isPresented and onChanged properties to control the visibility and behavior of the toast.
Example:
isPresented: Observable<boolean>
Description:
Uses the isPresented observable to control the visibility and behavior of the toast.
Example:
duration?: number | null
Description:
Specifies how long (in seconds) the toast should remain visible.
Defaults to 2 seconds.
Example:
position?: "top" | "bottom" | "center"
Description: Controls where the toast appears on the screen.
Available values:
"top"– Displays the toast at the top."bottom"– Displays the toast at the bottom (default)."center"– Displays the toast in the center.
Example:
backgroundColor?: Color | null
Description: Sets the background color of the toast.
Example:
textColor?: Color | null
Description: Sets the text color of the toast message.
Example:
cornerRadius?: number | null
Description:
Sets the corner radius of the toast.
Defaults to 16.
Example:
shadowRadius?: number | null
Description:
Sets the blur radius of the toast’s shadow.
Defaults to 4.
Example:
Displaying a Simple Message
Example:
When the button is pressed, a green toast with the message “Data saved successfully” appears at the bottom for 2 seconds.
Displaying Custom Content
Description:
Instead of plain text, you can provide a custom VirtualNode (view) as the toast content.
This allows you to include icons, multiple text lines, or other view layouts.
Example:
This example shows a custom toast with an icon and message inside a black rounded background.
Best Practices
-
Keep state synchronized Always ensure
isPresentedandonChangedstay in sync so the toast can be properly dismissed. -
Use for lightweight notifications Toasts should only display short, transient messages and should not include complex interactions.
-
Avoid multiple simultaneous toasts Displaying more than one toast at the same time may confuse users.
-
Combine with user actions Pair the toast with
Button,Form, or other components to provide quick feedback after an action.
